package com.exam.demo.util;

import com.exam.demo.controller.dto.UserDTO;
import com.exam.demo.entity.Admin;
import com.exam.demo.entity.Student;
import com.exam.demo.entity.Teacher;

/**
 * 功能描述
 * 把student、teacher、admin再次封装，传回前端
 *
 * @author yxj30
 * @date 2022/04/15  0:10
 */
public class ObjectMapper {
    public static UserDTO studentToUserDTO(Student student){
        UserDTO user = new UserDTO();
        user.setId(student.getId());
        user.setUserId(student.getStudentId());
        user.setUsername(student.getStudentName());
        user.setPassword(student.getStudentPassword());
        return user;
    }
    public static UserDTO teacherToUserDTO(Teacher teacher){
        UserDTO user = new UserDTO();
        user.setId(teacher.getId());
        user.setUserId(teacher.getTeacherId());
        user.setUsername(teacher.getTeacherName());
        user.setPassword(teacher.getTeacherPassword());
        return user;
    }

    public static UserDTO adminToUserDTO(Admin admin){
        UserDTO user = new UserDTO();
        user.setId(admin.getId());
        user.setUserId(admin.getAdminId());
        user.setUsername(admin.getAdminName());
        user.setPassword(admin.getAdminPassword());
        return user;
    }
}
